﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using He.Common;

namespace He.Web.manage.sitemap
{
    public partial class gen : Manage
    {
        string templateDir;
        TemplateHelper th;
        protected void Page_Load(object sender, EventArgs e)
        {
            chkLoginLevel("genSitemap");
            templateDir = PathHelper.MapPath(string.Format("~/{0}/sitemap/", webset.manage_path));
            th = new TemplateHelper(templateDir);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dic = LangHelper.GetLangDict();
            List<Model.channel> channels = new List<Model.channel>();
            foreach (KeyValuePair<string, string> item in dic)
            {
                List<Model.channel> clst = new BLL.channel().GetModelList(string.Format("lang='{0}' and is_lock=0", item.Key));
                channels.AddRange(clst);
            }

            th.Put("channels", channels);
            th.Put("this", this);
            th.Put("lang", new LangHelper());
            th.Put("html", new HtmlHelper());
            th.Put("biz", new BizHelper());

            if (cblSitemap.Items[0].Selected)
            {
                genHtml();
            }
            if (cblSitemap.Items[1].Selected)
            {
                genXml();
            }
            ShowSuccess("网站地图生成成功啦！", Request.RawUrl);
        }

        #region 生成HTML地图=================================
        private void genHtml()
        {
            th.Put("title", "网站地图-" + siteinfo.WebTitle);
            th.PageGeneration("sitemap.html", "~/", "sitemap.html");
        }
        #endregion

        #region 生成XML地图==================================
        private void genXml()
        {
            th.Put("channelDate", string.Format("{0}-01-01", DateTime.Now.Year));
            th.PageGeneration("sitemap.xml", "~/", "Sitemap.xml");
        }
        #endregion
    }
}